package com.gtapps.user.action;

import com.gtapps.user.entity.BaseUserUserEntity;
import com.gtapps.user.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.Validations;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller
@Scope("prototype")
@Namespace("/")
@ParentPackage("struts-default")
@Result(name = "input", location = "/html/input.jsp")
public class UserAction extends ActionSupport {


    private BaseUserUserEntity user;
    @Autowired
    private UserService userService;

    @Action(value = "add", results = {@Result(name = "success", location = "/html/success.jsp")})
    @Validations(requiredStrings = {
            @RequiredStringValidator(fieldName = "user.username", message = "品牌名称不允许为空!"),
            @RequiredStringValidator(fieldName = "user.password", message = "品牌唯一编码不允许为空!")})
    public String save() throws Exception {
        userService.saveUser(user);
        return SUCCESS;
    }

    public BaseUserUserEntity getUser() {
        return user;
    }

    public void setUser(BaseUserUserEntity user) {
        this.user = user;
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }
}
